var element = "";
layui
    .config({
        base: "../layui/exts/", //静态资源所在路径
    })
    .use(function () {
        var $ = layui.$;
        var treeTable = layui.treeTable;
        var util = layui.util;

        // 渲染
        var inst = treeTable.render({
            elem: '#dataTable',
            url: '/basic/getArchivesClassData',
            tree: {
                view: {
                    showIcon: false,
                    expandAllDefault: true
                },
            },
            size: "sm",
            height: "full-65",
            cols: [[
                {field: 'name', title: '分类名称', width: 280},
                {field: 'fullCode', title: '分类号', width: 180},
                {field: 'classifyName', title: '所属门类', width: 150},
                {field: 'fillingModel', title: '归档方式', width: 90, templet: "#fillingModelTpl"},
                {field: 'codeFormat', title: '档号格式', width: 300},
                {field: 'remark', title: '描述', width: 250},
                {fixed: "right", title: "操作", width: 100, toolbar: "#operationBar"}
            ]],
            page: false
        });

        util.on({
            newClass: function () {
                top.layer.open({
                    type: 2,
                    title: "设置档案分类",
                    content: "./basic/setArchivesClass?pid=&tid=&id=&parentId=",
                    area: ["500px", "430px"],
                    shadeClose: false,
                    resize: false,
                    btn: ['<i class="layui-icon">&#xe605;</i> 确定', '<i class="layui-icon">&#x1006;</i> 取消'],
                    yes: function (index, layero) {
                        var iframeWin = layero.find("iframe")[0];
                        if (iframeWin.contentWindow.Buttun_Submit()) {
                            inst.reload("dataTable");
                        }
                    },
                    btn2: function (index) {
                        layer.close(index);
                    },
                });
            },
        });

        treeTable.on("tool(dataTable)", function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case "addition":
                    top.layer.open({
                        type: 2,
                        title: "设置档案分类",
                        content: "./basic/setArchivesClass?pid=&tid=&id=&parentId=" + data.id,
                        area: ["500px", "430px"],
                        shadeClose: false,
                        resize: false,
                        btn: ['<i class="layui-icon">&#xe605;</i> 确定', '<i class="layui-icon">&#x1006;</i> 取消'],
                        yes: function (index, layero) {
                            var iframeWin = layero.find("iframe")[0];
                            if (iframeWin.contentWindow.Buttun_Submit()) {
                                inst.reload("dataTable");
                            }
                        },
                        btn2: function (index) {
                            layer.close(index);
                        },
                    });
                    return false;
                case "edit":
                    top.layer.open({
                        type: 2,
                        title: "设置档案分类",
                        content: "./basic/setArchivesClass?pid=&tid=&id=" + data.id + "&parentId=" + data.parentId,
                        area: ["500px", "430px"],
                        shadeClose: false,
                        resize: false,
                        btn: ['<i class="layui-icon">&#xe605;</i> 确定', '<i class="layui-icon">&#x1006;</i> 取消'],
                        yes: function (index, layero) {
                            var iframeWin = layero.find("iframe")[0];
                            if (iframeWin.contentWindow.Buttun_Submit()) {
                                inst.reload("dataTable");
                            }
                        },
                        btn2: function (index) {
                            layer.close(index);
                        },
                    });
                    return false;
                case "del":
                    top.layer.confirm("确定要删除当前选择的档案分类吗？ ", function (index) {
                        $.ajax({
                            url: "./delArchivesClass", //url
                            dataType: "json", //数据格式
                            type: "POST", //请求方式
                            async: false, //是否异步请求
                            data: {id: data.id},
                            success: function (result) {
                                if (result.code == 0) {
                                    treeTable.reload("dataTable");
                                    layer.close(index);
                                    top.parent.layer.msg(result.message, {icon: 1});
                                } else {
                                    top.parent.layer.alert(result.message, {icon: 2});
                                }
                            },
                        });
                        return false;
                    });
            }
        });

    });
